<!DOCTYPE html>
<html>
<head>
    <title>系统通知</title>
    <#include "/header.html">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <#if shiro.hasPermission("app:notice:save")>
        <button class="layui-btn layui-btn-normal" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 添加 </button>
        </#if>
    </div>
</script>

<script type="text/html" id="currentTableTargetTpl">
    {{# if(d.target == 2){ }}
    <span class="text-red">店铺</span>
    {{# } else if(d.target == 1){ }}
    <span class="text-blue">用户</span>
    {{# } else { }}
    <span class="text-black">全部</span>
    {{# } }}
</script>

<script type="text/html" id="currentTableStatusTpl">
    {{# if(d.status == 1){ }}
    <span class="layui-badge layui-bg-green">已发送</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-gray">未发送</span>
    {{# } }}
</script>

<script type="text/html" id="currentTableBar">
    <#if shiro.hasPermission("app:notice:save")>
    {{# if(d.status == 0){ }}
    <a class="layui-btn layui-btn-primary layui-border-green layui-btn-xs" lay-event="more">操作 <i class="layui-icon layui-icon-down"></i></a>
    {{# } }}
    </#if>
</script>

<script type="text/javascript">
    layui.use(['dropdown', 'form', 'table'], function () {
        var $ = layui.jquery,
            dropdown = layui.dropdown,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: serverUrl('app/notice/list'),
            toolbar: '#toolbarDemo',
            // defaultToolbar: ['filter'],
            cols: [[
                {type: "numbers", width: 60},
                {field: 'target', title: '接收人', minWidth: 150, templet: '#currentTableTargetTpl'},
                {field: 'title', title: '标题', minWidth: 150},
                {field: 'content', title: '内容', minWidth: 280, templet: function(d){return d.content.replace(/\n/g,"<br/>")}},
                {field: 'noticeTime', title: '通知时间', width: 180},
                {field: 'status', title: '状态', width: 120, templet: '#currentTableStatusTpl'},
                {field: 'createTime', title: '创建时间', width: 180},
                {title: '操作', width: 100, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [15, 30, 50],
            limit: 15,
            page: true
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                formDataId = 0;
                openFormView('app/notice/form.html', '添加通知');
            }
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var that = this;
            var data = obj.data;
            if(obj.event === 'more'){
                //更多下拉菜单
                dropdown.render({
                    elem: that
                    ,show: true //外部事件触发即显示
                    ,data: [{
                        title: '编辑'
                        ,templet: '<span class="text-blue"><i class="layui-icon layui-icon-edit"></i>{{d.title}}</span>'
                        ,id: 'edit'
                    }, {
                        title: '删除'
                        ,templet: '<span class="text-red"><i class="layui-icon layui-icon-close"></i>{{d.title}}</span>'
                        ,id: 'del'
                    }]
                    ,click: function(res, othis){
                        if (res.id == 'edit') {
                            formDataId = data.id;
                            openFormView('app/notice/form.html', '编辑通知');

                        } else {
                            layer.confirm('确定删除吗？', function (index) {
                                deleteTableRow('app/notice/delete', [data.id], function (rs) {
                                    obj.del();
                                });
                                layer.close(index);
                            });
                        }
                    }
                });
            }
        });

        // 监听搜索操作
        initSearchForm('searchForm', 'currentTableId');

    });
</script>

</body>
</html>